<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    Function.prototype.call = function (context) {
      if (typeof this !== 'function') {
        throw new TypeError('Error')
      }
      context = context || window;
      context.fn = this;

      const args = [...arguments].slice(1);
      const result = context.fn(...args)
      delete context.fn
      return result;
    }
    console.log(Math.max.call(null, 1, 2, 3));

    Function.prototype.apply = function (context) {
      if (typeof this !== 'function') {
        throw new TypeError('Error');
      }
      console.log(arguments);

      context = context || window;
      context.fn = this;
      let result;
      if (arguments[1]) {
        result = context.fn(...arguments[1])
      } else {
        result = context.fn()
      }
      delete context.fn;
      return result;
    }
    console.log(Math.max.apply(null, [1, 2, 3]));


    Function.prototype.myBind = function (context) {
      if (typeof this !== 'function') {
        throw new TypeError('Error');
      }
      const _this = this;
      const args = [...arguments].slice(1);
      return function F() {
        if (this instanceof F) {
          return new _this(...args, ...arguments);
        }
        return _this.apply(context, args.concat(...arguments));
      }
    }
  </script>
</body>

</html>